home *** CD-ROM | disk | FTP | other *** search
- Path: hobbes.cc.uga.edu!news
- From: Andy Dustman <andy@CCMSD.chem.uga.edu>
- Newsgroups: comp.lang.c++
- Subject: Re: Template troubles with partial solution (?)
- Date: Thu, 04 Apr 1996 11:52:37 -0500
- Organization: University of Georgia, Athens
- Message-ID: <3163FE55.3E74EA5F@CCMSD.chem.uga.edu>
- References: <316354F3.7DEA1F8@CCMSD.chem.uga.edu>
- NNTP-Posting-Host: neptune.chem.uga.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; Linux 1.3.80 i586)
- CC: andy@ccmsd.chem.uga.edu
-
- Andy Dustman wrote:
- >
- > I'm trying to modify an existing library of matrix routines into a template
- > and I'm having lots of trouble. I'm using G++ 2.7.0, but 2.7.2 seems to have
- > the same problems.
-
- [deletia]
-
- > matrix.h:
- >
- > template<class T>
- > class matrix {
- > T* mat;
- > ...
- > matrix<T>& operator+= (const matrix<T>& m);
- > ...
- > } ;
- > template<class T> matrix<T> operator+ (const matrix<T>& m, const matrix<T>& n); \\ A
- >
- > *********
- > matrix.c:
- >
- > #include "matrix.h"
- >
- > template<class T> matrix<T> matrix<T>::operator+= (const matrix<T>& m);
- > { ... }
- >
- > template<class T> matrix<T> operator + (const matrix& m, const matrix& n) \\ B
- > {
- > matrix<T> p = m;
- > p += n;
- > return p;
- > }
- >
- > **********
- > dmatrix.c:
- >
- > #include "matrix.c"
- >
- > template class matrix<double>;
- >
- > This compiles, but at link time, I get:
- >
- > test.o(.text+0x14d): undefined reference to `operator+(matrix<double> const &, matrix<double> const &)'
-
- Somebody sent me some code that is defined essentially the same way. It
- compiles and it works. The difference is that his code was all in one file.
- So I changed my main.c (not shown) to #include "matrix.c" and not "matrix.h"
- so that it would create the template instance matrix<double> within the same
- object file. THIS works. But I can't compile a separate object file (like
- matrix.c) and get it to link, and as a practical matter, I need to do that.
-
- This is with G++ 2.7.0, and I have tried using the -fno-implicit-templates
- switch, and that works even worse (even more unresolved symbols). I've also
- tried using #pragma directives and -f{alt-}external-templates, with pretty
- much the same results. Any suggestions?
-
- --
- Andy Dustman / Computational Center for Molecular Structure and Design / UGA
- ===== For PGP public key: finger andy@neptune.chem.uga.edu | pgp -fka =====
- Sure, the Telecomm Act will create jobs: 100,000 new thought-cops on the net
- http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++<
-